﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="FoodLight.CategoryPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:local="using:FoodLight"
    xmlns:data="using:FoodLight.Data"
    xmlns:common="using:FoodLight.Common"
    xmlns:tiles="using:FoodLight.VariableTemplate"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">


    <Page.TopAppBar>
        <AppBar x:Name="appBar2" Padding="10,0,10,0" Background="#AC000000" BorderBrush="{x:Null}" MinHeight="88">
            <Grid Margin="0" >
                <StackPanel Margin="110,10,0,10" Orientation="Horizontal" HorizontalAlignment="Left" Height="90">
                    <Button x:Name="btnTopApp" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0" Style="{StaticResource TopButton}" Tapped="btnTopApp_Tapped_1">
                        <Image Width="85" Height="88" Source="Assets/TopApp1.png"/>
                    </Button>
                    <Button x:Name="btnTopApp2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0" Style="{StaticResource TopButton}" Margin="10,0,0,0">
                        <Image Width="85" Height="88" Source="Assets/TopApp2.png"/>
                    </Button>
                    <Button x:Name="btnTopApp3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0" Style="{StaticResource TopButton}" Margin="10,0,0,0">
                        <Image Width="85" Height="88" Source="Assets/TopApp3.png"/>
                    </Button>
                    <Button x:Name="btnTopApp4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0" Style="{StaticResource TopButton}" Margin="10,0,0,0">
                        <Image Width="85" Height="88" Source="Assets/TopApp4.png"/>
                    </Button>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.TopAppBar>

    <Page.Resources>

        <!--
            Collection of grouped items displayed by this page, bound to a subset
            of the complete item list because items in groups cannot be virtualized
        -->
        <CollectionViewSource
             x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="TopItems"
            d:Source="{Binding AllGroups, Source={d:DesignInstance Type=data:CategoryDataSource, IsDesignTimeCreatable=True}}"/>


        <tiles:VariableTiles x:Key="MyTemplateSelectorObj" 
                             
                             RecipesBigTemplate="{StaticResource CateryBigItemTemplate}"
                             RecipesSmallTemplate="{StaticResource RecipesSmallItemTemplate}"
                             CuisinesTemplate="{StaticResource CuisinesItemTemplate}"
                             DishSmallTemplate="{StaticResource DishSmallItemTemplate}"
                             PopularBigTemplate="{StaticResource PopularBigItemTemplate}"
                             PopularBigsceTemplate="{StaticResource PopularBigsceItemTemplate}"
                             PopularSmallTemplate="{StaticResource PopularSmallItemTemplate}"
                             PopularSmallsecTemplate="{StaticResource PopularSmallsecItemTemplate}"
                             CateryBigTemplate="{StaticResource CateryBigItemTemplate}">


        </tiles:VariableTiles>
        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">My Application</x:String>
        <Style x:Key="CatrButtonStyle" TargetType="Button">
        	<Setter Property="MinWidth" Value="0"/>
        	<Setter Property="Width" Value="48"/>
        	<Setter Property="Height" Value="48"/>
        	<Setter Property="Margin" Value="36,0,36,36"/>
        	<Setter Property="VerticalAlignment" Value="Bottom"/>
        	<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
        	<Setter Property="FontWeight" Value="Normal"/>
        	<Setter Property="FontSize" Value="56"/>
        	<Setter Property="AutomationProperties.AutomationId" Value="BackButton"/>
        	<Setter Property="AutomationProperties.Name" Value="Back"/>
        	<Setter Property="AutomationProperties.ItemType" Value="Navigation Button"/>
        	<Setter Property="Template">
        		<Setter.Value>
        			<ControlTemplate TargetType="Button">
        				<Grid x:Name="RootGrid">

        					<VisualStateManager.VisualStateGroups>
        						<VisualStateGroup x:Name="CommonStates">
        							<VisualState x:Name="Normal" />
        							<VisualState x:Name="PointerOver">
        								<Storyboard>
        									<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
        										<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonPointerOverBackgroundThemeBrush}"/>
        									</ObjectAnimationUsingKeyFrames>
        								</Storyboard>
        							</VisualState>
        							<VisualState x:Name="Pressed">
        								<Storyboard>
        									<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
        										<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonForegroundThemeBrush}"/>
        									</ObjectAnimationUsingKeyFrames>
        									<DoubleAnimation
        										Storyboard.TargetName="ArrowGlyph"
        										Storyboard.TargetProperty="Opacity"
        										To="1"
        										Duration="0"/>
        									<DoubleAnimation
        										Storyboard.TargetName="NormalGlyph"
        										Storyboard.TargetProperty="Opacity"
        										To="0"
        										Duration="0"/>
        								</Storyboard>
        							</VisualState>
        							<VisualState x:Name="Disabled">
        								<Storyboard>
        									<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Visibility">
        										<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
        									</ObjectAnimationUsingKeyFrames>
        								</Storyboard>
        							</VisualState>
        						</VisualStateGroup>
        						<VisualStateGroup x:Name="FocusStates">
        							<VisualState x:Name="Focused">
        								<Storyboard>
        									<DoubleAnimation
        										Storyboard.TargetName="FocusVisualWhite"
        										Storyboard.TargetProperty="Opacity"
        										To="1"
        										Duration="0"/>
        									<DoubleAnimation
        										Storyboard.TargetName="FocusVisualBlack"
        										Storyboard.TargetProperty="Opacity"
        										To="1"
        										Duration="0"/>
        								</Storyboard>
        							</VisualState>
        							<VisualState x:Name="Unfocused" />
        							<VisualState x:Name="PointerFocused" />
        						</VisualStateGroup>
        					</VisualStateManager.VisualStateGroups>
        					<Grid Margin="-1,-16,0,0">
        						<TextBlock x:Name="BackgroundGlyph" Text="&#xE0A8;" Foreground="{StaticResource BackButtonBackgroundThemeBrush}"/>
        						<TextBlock x:Name="NormalGlyph" Text="{StaticResource BackButtonGlyph}" Foreground="Black"/>
        						<TextBlock x:Name="ArrowGlyph" Text="&#xE0A6;" Foreground="Black" Opacity="0"/>
        					</Grid>
        					<Rectangle
        						x:Name="FocusVisualWhite"
        						IsHitTestVisible="False"
        						Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
        						StrokeEndLineCap="Square"
        						StrokeDashArray="1,1"
        						Opacity="0"
        						StrokeDashOffset="1.5"/>
        					<Rectangle
        						x:Name="FocusVisualBlack"
        						IsHitTestVisible="False"
        						Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
        						StrokeEndLineCap="Square"
        						StrokeDashArray="1,1"
        						Opacity="0"
        						StrokeDashOffset="0.5"/>

        				</Grid>
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>
        </Style>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Horizontal scrolling grid used in most view states -->
        <!--<GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Grouped Items"
            Grid.RowSpan="2"
            Padding="116,137,40,46"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="false">

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>                        
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,6">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                    Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>-->

        <tiles:VariableTileControl Grid.Row="1"
        	x:Name="itemGridView"
        	AutomationProperties.AutomationId="ItemGridView"
        	AutomationProperties.Name="Grouped Items"
        	Padding="120,0,40,20"
        	ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
        	ItemTemplateSelector="{StaticResource MyTemplateSelectorObj}"
        	SelectionMode="None"
        	IsItemClickEnabled="True"
        	ItemClick="ItemView_ItemClick" HorizontalContentAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Auto">
        	<tiles:VariableTileControl.Background>
        		<ImageBrush ImageSource="Assets/Bg2.png"/>
        	</tiles:VariableTileControl.Background>

            <tiles:VariableTileControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </tiles:VariableTileControl.ItemsPanel>
            <tiles:VariableTileControl.GroupStyle>
                <GroupStyle >
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <StackPanel Margin="1,0,0,6" Orientation="Horizontal">
                                <Button
        							AutomationProperties.Name="Group Title"
        							Content="{Binding Title}"
        							Click="Header_Click"
        							Style="{StaticResource TextButtonStyle}" FontWeight="Light" Foreground="Black" FontSize="26.667" Background="#FFD71921" BorderBrush="Black"/>
                                <!--<TextBlock x:Name="txtVideo" HorizontalAlignment="Right" TextWrapping="Wrap" Text="{Binding Sub}" VerticalAlignment="Bottom" Foreground="#FFC4261D" Margin="140,21,0,0" FontFamily="Segoe UI" FontSize="16" Visibility="{Binding SubTl}"/>
                                <TextBlock x:Name="txtPicture" HorizontalAlignment="Right" TextWrapping="Wrap" Text="{Binding Sub2}" VerticalAlignment="Bottom" Foreground="#FFC4261D" Margin="275,21,0,0" FontFamily="Segoe UI" FontSize="16" Visibility="{Binding SubT2}"/>-->
                            </StackPanel>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid ItemHeight="5" ItemWidth="5" MaximumRowsOrColumns="110" Orientation="Vertical" Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </tiles:VariableTileControl.GroupStyle>
        </tiles:VariableTileControl>

        <!-- Vertical scrolling list only used when snapped -->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemListView"
            AutomationProperties.Name="Grouped Items"
            Grid.Row="1"
            Visibility="Collapsed"
            Margin="0,-10,0,0"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplate="{StaticResource Standard80ItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemView_ItemClick">

            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="7,7,0,0">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                    Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" Foreground="Black" />
                                        <!--<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}" Foreground="Black"/>-->
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource CatrButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}" Foreground="#DE000000" Text="Recipes"/>
            <Grid x:Name="LogoGrid" HorizontalAlignment="Right" Height="100" VerticalAlignment="Center" Width="234" Grid.Column="1" Margin="0,0,40,0">
            	<Image Source="Assets/AppLogo.png"/>
            </Grid>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,0,10,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="LogoGrid">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="appBar2">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    	<DoubleAnimation Duration="0" To="40" Storyboard.TargetProperty="(TextBlock.FontSize)" Storyboard.TargetName="pageTitle" d:IsOptimized="True"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
